﻿#include <iostream>
#include "BinaryTree.h"

#define MAX(a, b) (a > b ? a : b)

static int recur(BinaryTreeNode* head)
{
    if (!head) return 0;

    int left = recur(head->left);
    int right = recur(head->right);
    return MAX(left, right) + head->getValue();
}

// 二叉树每个节点都有一个int型权值，给定一颗二叉树，要求计算出从根节点到叶节点的所有路径中，权值和的最大值是多少。
int main_MaxPower()
{
    auto head = new BinaryTreeNode(10);
    head->left = new BinaryTreeNode(7);
    head->right = new BinaryTreeNode(15);
    head->left->left = new BinaryTreeNode(3);
    head->left->right = new BinaryTreeNode(9);
    head->right->left = new BinaryTreeNode(12);
    head->right->right = new BinaryTreeNode(18);
    head->right->left->right = new BinaryTreeNode(14);

    int maxPower = recur(head);
    printf("%d\n", maxPower);
    deleteBinaryTree(head);

    return 0;
}